﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Kugar.Core.ExtMethod;

namespace Kugar.ERPFramework.View.WinForm
{
    public partial class ModuleDataEditorBase : ModuleFormBase
    {
        protected object ModuleControler = null;


#if DEBUG
        public ModuleDataEditorBase()
#else
        protected ModuleDataEditorBase()
#endif
        {
            InitializeComponent();
        }

        public ModuleDataEditorBase(object moduleControler):this()
        {
            ModuleControler = moduleControler;
        }

        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                if (lblCaption!=null)
                {
                    lblCaption.Text = value.ToStringEx();
                }
                
                base.Text = value.ToStringEx();
            }
        }


        /// <summary>
        ///     由继承类实现的功能,用于判断界面上的数据是否已修改<br/>
        ///     如果实现的类为不需要数据保存功能的,则不需要重载该函数
        /// </summary>
        /// <returns></returns>
        protected virtual bool IsChanged()
        {
            return false;
        }

        /// <summary>
        ///     实现数据保存的函数,由继承的窗体实现
        /// </summary>
        protected virtual void Save()
        {
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            if (IsChanged())
            {
                if (ShowMessageWithButton("是否保存?"))
                {
                    Save();
                }

            }
            base.OnFormClosing(e);
        }
    }
}
